using System;
using System.Collections.Generic;

namespace Framework
{
    public class PoolInfo
    {
        public static int ID;
        private static readonly List<PoolInfo> _all = new(30);
        private static int _id = 1;
        public Type TargetType { get; private set; }
        public string Type { get; private set; }
        public string Name;
        public int ActiveCount { get; protected set; }
        public int UnusedCount { get; protected set; }
        private int id;

        public PoolInfo(Type target)
        {
            TargetType = target;
            this.Name = target.Name;
            this.Type = target.FullName;
            ActiveCount = UnusedCount = 0;
            if (target.IsGenericType)
            {
                this.Type = this.Name;
                var splitid = this.Name.IndexOf("`");
                if (splitid != -1)
                {
                    this.Type = this.Name.Substring(0, splitid);
                    this.Name = this.Type;
                }
                this.Type += "<";
                var len = target.GenericTypeArguments.Length;
                for (int i = 0; i < len; i++)
                {
                    if (i > 0)
                    {
                        this.Type += ",";
                    }
                    this.Type += target.GenericTypeArguments[i].Name;
                }
                this.Type += ">";
            }
            _all.Add(this);
            id = _id++;
        }
        public static void Foreach(List<PoolInfo> target)
        {
            ID = 0;
            foreach (var item in _all)
            {
                ID += 100000 * item.id + item.ActiveCount;
                target.Add(item);
            }

        }
    }
}